using System;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.XPath;
using System.Xml.Xsl;

namespace newtelligence.DasBlog.Web
{
	public class BlogRollControl : UserControl
	{
		protected PlaceHolder contentPlaceHolder;

		public BlogRollControl()
		{
		}

		private void Page_Load(object sender, EventArgs e)
		{
			// Load up the OPML
			string opmlPath = HttpContext.Current.Server.MapPath("siteconfig\\blogroll.opml");
			string xsltPath = HttpContext.Current.Server.MapPath("siteconfig\\opml.xslt");

			XPathDocument xmlOpml = new XPathDocument(opmlPath);
			XslTransform xmlTransform = new XslTransform();

			// Load up the files
			xmlTransform.Load(xsltPath);

			// Transform
			StringWriter sw = new StringWriter();
			xmlTransform.Transform(xmlOpml, null, sw, null);

			contentPlaceHolder.Controls.Add(new LiteralControl(sw.ToString()));
			sw.Close();

			DataBind();
		}

		protected override void OnInit(EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}

		private void InitializeComponent()
		{
			this.Load += new EventHandler(this.Page_Load);
		}
	}
}